<?php

namespace app\api\controller;

use app\common\controller\Api;
use QL\QueryList;
use GuzzleHttp\Cookie\CookieJar;

/**
 * 工具箱接口📦
 * 
 */
class Tool extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 测试方法
     *
     * @ApiTitle    (测试名称)
     * @ApiSummary  (测试描述信息)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/demo/test/id/{id}/name/{name})
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="integer", required=true, description="会员ID")
     * @ApiParams   (name="name", type="string", required=true, description="用户名")
     * @ApiParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
         'code':'1',
         'msg':'返回成功'
        })
     */
    protected function test()
    {
        $this->success('返回成功', $this->request->param());
    }

    /**
     * 在线识别二维码💮
     * 
     * @ApiSummary  (如果识别有问题请联系QQ496631085)
     *
     * @param string $url 二维码地址🏞
     * @param string $json 默认非返回非json格式
     * @return void
     */
    public function url_de_qrcode($url=null,$json=null)
    {
        $geturl = 'https://jiema.wwei.cn/wwei/file/decodeQrcodeImage';
        if($url){
            if (filter_var($url, FILTER_VALIDATE_URL) !== false) {

            }else{
                $this->error('图片地址不正确');
            }
        }



        $headers1 = [
            //'Cookie'=>$_COOKIE,
        'User-Agent'    => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
        'Content-Type'  => 'application/x-www-form-urlencoded; charset=UTF-8'];


        $headers2 = [
            //'Cookie'=>$_COOKIE,
        'User-Agent'    => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36',
        'Content-Type'  => 'application/x-www-form-urlencoded; charset=UTF-8',
        'X-Requested-With' => 'XMLHttpRequest'];

    
        $data = QueryList::get('https://jiema.wwei.cn/url.html',null,['headers'=>$headers1]);

 
        $post['img']=$url;
        $post['filename'] = null;
        $post['de_type'] = 'url';
        $post['_token'] = $data->find('meta[name=csrf-token]')->content;

        $ql = $data->post($geturl,$post,['headers'=>$headers2]);
        $str = $ql->getHtml();

        $json_data = json_decode($str,true);
        if($json_data['status']==1){
            if($json){
                $this->success($json_data['info'], $json_data['content'][0][0]);
            }else{
                echo $json_data['content'][0][0];
            }
            
        }else{
            $this->error('失败,请联系QQ496631085');
        }

        
    }


    
    /**
     * 时间戳转日期🔢👉📅
     *
     * @param integer $time 时间戳🔢
     * @return void
     */
    public function time_stamp_to_date($time=null)
    {   

        $this->success('ok', date('Y-m-d H:i:s',$time));
    }


    /**
     * 日期转时间戳📅👉🕓
     *
     * @param integer $date 日期📆
     * @return void
     */
    public function date_to_time_stamp($date=null)
    {

        $this->success('ok', strtotime($date));
    }

    /**
     * 获取我当前网络的ip地址🖥
     *
     * @param integer $str 只获取字符串默认假
     * @return void
     */
    public function get_my_ip($str=null)
    {
        $ip = $this->request->ip();
        if($str){
            echo $ip;
        }else{
            $this->success('ok',$ip);
        }
    }


   

}
